package com.base.dataStructure.recurrence;

/**
 * @Author: hdhao
 * @Create: 2023/3/28 - 20:41
 * @Version: v1.0
 */
//使用递归完成二分查找
public class BinarySearch {
    public static void main(String[] args) {
        int[] a = {7,13,14,21,30,38,44,52};
        int res = search(a, 14, 0, a.length - 1);
        System.out.println(res);
    }

    public static int search(int[] a, int target,int i,int j){
        if (i >j){
            return -1;
        }
        int m = (i+j)/2;
        if (target<a[m]){
            return search(a,target,i,m-1);
        }else if(a[m]<target){
            return search(a,target,m+1,j);
        }else {
            return m;
        }
    }
}
